<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import {ref, reactive} from 'vue'
import corp from '@/api/backend/corp.js'
import {Message} from '@arco-design/web-vue'
import tool from '@/utils/tool.js'
import * as common from '@/utils/common.js'

const crudRef = ref()


const switchStatus = (statusValue, id, statusName) => {
  corp.changeStatus({id, statusName, statusValue}).then(res => {
    res.success && Message.success(res.message)
  }).catch(e => {
    console.log(e)
  })
}


const options = reactive({
  id: 'corp_corp',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  api: corp.getList,
  recycleApi: corp.getRecycleList,
  add: {
    show: true,
    api: corp.save,
    auth: ['corp::save']
  },
  edit: {
    show: true,
    api: corp.update,
    auth: ['corp::update']
  },
  delete: {
    show: true,
    api: corp.deletes,
    auth: ['corp::delete'],
    realApi: corp.realDeletes,
    realAuth: ['corp::realDeletes']
  },
  recovery: {
    show: true,
    api: corp.recoverys,
    auth: ['corp::recovery']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "公司名称",
    dataIndex: "name",
    formType: "input",
    search: true
  },
  {
    title: "企业号",
    dataIndex: "no",
    formType: "input",
    search: true
  },
  {
    title: "所属账户",
    dataIndex: "user_id",
    formType: "select",
    multiple: false,
    dict: {
      remote: 'backend/account/remote',
      method: 'post',
      props: {label: 'phone', value: 'gene_id'},
      remoteOption: {
        select: ['gene_id', 'phone']
      },
      translation: true
    },
    search: true,
    editDisplay: false,
  }
])
</script>
<script> export default {name: 'corp'} </script>